﻿@model FineAdmin.Model.AdZoneModel
@{ ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutForm.cshtml"; }

<form class="layui-form layui-form-pane ok-form" lay-filter="formTest">
    @*一些不需要更新的隐藏字段*@
    @Html.HiddenFor(x => x.Id)
    @Html.HiddenFor(x => x.CreateTime)
    @Html.HiddenFor(x => x.CreateUserId)
    
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="Name" placeholder="名称" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">PID</label>
        <div class="layui-input-block">
            <input type="text" name="Pid" placeholder="PID" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">TBK_AdzoneId</label>
        <div class="layui-input-block">
            <input type="text" name="TBK_AdzoneId" placeholder="TBK_AdzoneId" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">TBK_AppKey</label>
        <div class="layui-input-block">
            <input type="text" name="TBK_AppKey" placeholder="TBK_AppKey" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">TBK_AppSecret</label>
        <div class="layui-input-block">
            <input type="text" name="TBK_AppSecret" placeholder="TBK_AppSecret" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="text" name="Type" placeholder="1 TB 2 JD 3 PDD " autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    @*<div class="layui-form-item">
        <label class="layui-form-label">小图标</label>
        <div class="layui-input-block">
            <input type="text" name="Icon_S" placeholder="小图标" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>*@
    <div class="layui-form-item">
        <label class="layui-form-label">默认推广位</label>
        <div class="layui-input-block">
            @*<input type="checkbox" id="ShowWeb" name="ShowWeb" placeholder="是否在PC端展示" autocomplete="off" class="layui-input">*@
            <input type="checkbox" name="IsDefault" lay-skin="switch" lay-filter="" title="开/关" value="True" lay-text="ON|OFF"
                   @((Model.IsDefault.HasValue && Model.IsDefault.Value) ? "checked" : "")>
        </div>
    </div>
   
    
    <div class="layui-form-item">
        <label class="layui-form-label">排序码</label>
        <div class="layui-input-block">
            <input type="text" name="SortCode" placeholder="排序码" autocomplete="off" class="layui-input" lay-verify="number" maxlength="2">
        </div>
    </div>
    @*<div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                @Html.DropDownList("CategoryId", (IEnumerable<SelectListItem>)ViewBag.CategoryNameList, "请选择分类", new Dictionary<string, object> { { "lay-verify", "required" } })
            </div>
        </div>*@
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(["form", "treeSelect", "okLayer", "okUtils"], function () {
        let treeSelect = layui.treeSelect;
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
       
        //给表单赋值
        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "Name": "@Model.Name",
            "Pid": "@Model.Pid",
            "SortCode": "@Model.SortCode",
            "TBK_AppKey": "@Model.TBK_AppKey",
            "TBK_AdzoneId": "@Model.TBK_AdzoneId",
            "TBK_AppSecret": "@Model.TBK_AppSecret",
            "Type": "@Model.Type",

        });
        form.on("submit(add)", function (data) {
            okUtils.ajax("/Shop/AdZoneSet/Edit", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.message, function () {
                    parent.location.reload(); // 父页面刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>

